#include<bits/stdc++.h> 
using namespace std;
int row, col;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
bool check[1501][1501];
bool cmp = false;
bool DFS(vector<vector<char>>& grid, int i, int j)
{
    check[i][j] = true;
    if (i == 0 || j == 0 || i == row - 1 || j == col - 1) return true;
    for (int k = 0; k < 4; k++)
    {
        int x = i + dx[k], y = j + dy[k];
        if (x >= 0 && x < row && y >= 0 && y < col && !check[x][y] && grid[x][y] == '.')
        {
            cmp = DFS(grid, x, y);
        }
    }
    return cmp;
}
bool solution(vector<vector<char>>& grid, int sr, int sc)
{
    if (sr == 0 || sc == 0 || sr == row - 1 || sc == col - 1) return false;
    return DFS(grid, sr, sc);
    return false;

}
int main()
{
    int st = 0, ed = 0;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> row >> col;
    vector<vector<char>> grid(row, vector<char>(col));
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
        {
            cin >> grid[i][j];
            if (grid[i][j] == 'S')
            {
                st = i, ed = j;
            }
        }
    }
    auto ret = solution(grid, st, ed);
    if (ret) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}